<template>
  <div class="home">
    <div style="margin-left: 100px;"class="statistic">
      <el-row :gutter="16">
    <el-col :span="8">
      <div class="statistic-card">
        <el-statistic :value="98500">
          <template #title>
            <div style="display: inline-flex; align-items: center">
             总浏览数/pv
              <el-tooltip
                effect="dark"
                content="Number of users who logged into the product in one day"
                placement="top"
              >
                <el-icon style="margin-left: 4px" :size="12">
                  <Warning />
                </el-icon>
              </el-tooltip>
            </div>
          </template>
        </el-statistic>
        <div class="statistic-footer">
          <div class="footer-item">
            <span>这周</span>
            <span class="green">
              24%
              <el-icon>
                <CaretTop />
              </el-icon>
            </span>
          </div>
        </div>
      </div>
    </el-col>
    <el-col :span="8">
      <div class="statistic-card">
        <el-statistic :value="69370">
          <template #title>
            <div style="display: inline-flex; align-items: center">
              总访客数/UV
              <el-tooltip
                effect="dark"
                content="Number of users who logged into the product in one month"
                placement="top"
              >
                <el-icon style="margin-left: 4px" :size="12">
                  <Warning />
                </el-icon>
              </el-tooltip>
            </div>
          </template>
        </el-statistic>
        <div class="statistic-footer">
          <div class="footer-item">
            <span>这周</span>
            <span class="red">
              12%
              <el-icon>
                <CaretBottom />
              </el-icon>
            </span>
          </div>
        </div>
      </div>
    </el-col>
    <el-col :span="8">
      <div class="statistic-card">
        <el-statistic :value="72000" title="New transactions today">
          <template #title>
            <div style="display: inline-flex; align-items: center">
              总访问次数/VV
            </div>
          </template>
        </el-statistic>
        <div class="statistic-footer">
          <div class="footer-item">
            <span>这周</span>
            <span class="green">
              16%
              <el-icon>
                <CaretTop />
              </el-icon>
            </span>
          </div>
          <div class="footer-item">
            <el-icon :size="14">
              <ArrowRight />
            </el-icon>
          </div>
        </div>
      </div>
    </el-col>
  </el-row>
    </div>
    <div  class="login">
      <div  class="login" ref="lineChartRef" style="width:100%; height: 320px; margin-left: 20px; margin-top: 20px"></div>
    </div>
    <div class="course" ref="barChartRef" style="width:100%; height: 320px;margin-left: 20px; margin-top: 20px" ></div>
  </div>
</template>

<script setup>
import { ref, onMounted, onBeforeUnmount } from 'vue';
import * as echarts from 'echarts';
import {
  ArrowRight,
  CaretBottom,
  CaretTop,
  Warning,
} from '@element-plus/icons-vue'
const barChartRef = ref(null);
const lineChartRef = ref(null);
let barChart = null;
let lineChart = null;

onMounted(() => {
  drawBarChart();
  drawLineChart();
});

const drawBarChart = () => {
  barChart = echarts.init(barChartRef.value);

  const barOption = {
    title: {
      text: '课程销售'
    },
    tooltip: {},
    legend: {
      data: ['销量']
    },
    xAxis: {
      data: ['javascript', 'jquery', 'java', 'C++', '编程语言', 'springBot', 'MySQL', 'Linux', 'Docker', 'MongoDB', 'Hadoop', 'Spark', '云计算']
    },
    yAxis: {},
    series: [
      {
        name: '销量',
        type: 'bar',
        data: [1000, 2000, 3600, 1000, 1000, 1230, 1222, 532, 1035, 664, 743, 1233, 2323]
      }
    ]
  };

  barChart.setOption(barOption);
};

const drawLineChart = () => {
  lineChart = echarts.init(lineChartRef.value);

  const lineOption = {
    title: {
      text: '14天登录人数（折线图）'
    },
    tooltip: {},
    legend: {
      data: ['登录人数']
    },
    xAxis: {
      data: ['2024-05-07', '2024-05-08', '2024-05-09', '2024-05-10', '2024-05-11', '2024-05-12', '2024-05-13', '2024-05-14', '2024-05-15', '2024-05-16', '2024-05-17', '2024-05-18', '2024-05-19','2024-05-20','2024-05-21']
    },
    yAxis: {},
    series: [
      {
        name: '登录人数',
        type: 'line',
        data: [12, 22, 35, 44, 33, 66, 100, 23, 77, 26, 88, 53, 43,45,33]
      }
    ]
  };

  lineChart.setOption(lineOption);
};

const updateData = (newData) => {
  if (barChart && lineChart) {
    barChart.setOption({
      series: [
        {
          data: newData
        }
      ]
    });
    lineChart.setOption({
      series: [
        {
          data: newData
        }
      ]
    });
  }
};
</script>

<style lang="less" scoped>
.home {
  .course {
    background-color: #f4f4f5;
  }
  :global(h2#card-usage ~ .example .example-showcase) {
  background-color: var(--el-fill-color) !important;
}

.el-statistic {
  --el-statistic-content-font-size: 28px;
}

.statistic-card {
  height: 100%;
  padding: 20px;
  border-radius: 4px;
  background-color: var(--el-bg-color-overlay);
}

.statistic-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--el-text-color-regular);
  margin-top: 16px;
}

.statistic-footer .footer-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.statistic-footer .footer-item span:last-child {
  display: inline-flex;
  align-items: center;
  margin-left: 4px;
}

.green {
  color: var(--el-color-success);
}
.red {
  color: var(--el-color-error);
}
}
</style>
